package ui

import applicationModel.Plantar
import dominio.JardinTablero
import dominio.Jugador
import dominio.Planta
import org.eclipse.swt.SWT
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner

class PlantarWindow extends Dialog<Plantar> {

	@Property JardinTablero jt
	@Property Jugador jug

	new(WindowOwner owner, Plantar plantar, JardinTablero jart, Jugador jug) {
		super(owner, plantar)
		title = "Defiende una fila!!"
		taskDescription = "Elige las plantas"
		jt = jart
		_jug = jug
	}

	override protected createFormPanel(Panel mainPanel) {
		val editorPanel = new Panel(mainPanel)
		editorPanel.setLayout(new ColumnLayout(2))

		new Label(editorPanel).text = "Plantar A: "
		val selectorPlanta = new Selector<Planta>(editorPanel).allowNull(false)
		selectorPlanta.bindValueToProperty("plantaAPlantar")
		var propPlantas = selectorPlanta.bindItems(new ObservableProperty(jug, "plantas"))
		propPlantas.adapter = new PropertyAdapter(typeof(Planta), "descripcionEntera")

	}

	override addActions(Panel actionsPanel) {
		val botonJugar = new Button(actionsPanel).setAsDefault.setCaption("Plantar")
		botonJugar.onClick[|this.plantar]
		botonJugar.bindEnabled(new NotNullObservable("plantaAPlantar"))
		botonJugar.disableOnError

		val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
		botonvolver.onClick[|cancel]

	}

	def plantar() {
		modelObject.agregar()
		jt.refresh
	}

	/*override showError(String message) {
		this.showMessageBox(message, SWT.OK.bitwiseOr(SWT.ICON_ERROR))
	}*/

}
